package com.dc.seckill.result;

/**
 * 
 * @模块 参数模块
 * @作者 djs
 * @时间 2018年3月6日
 * @版本 1.0
 * @描述 全局返回码及返回参数集合对象
 */
public class CodeMsg {
	
	private int code;	//返回码
	private String msg;	//返回信息
	
	//通用错误
	public static CodeMsg SUCCESS = new CodeMsg(0,"success");
	public static CodeMsg SERVER_ERROR = new CodeMsg(500100,"服务端异常");
	public static CodeMsg BIND_ERROR = new CodeMsg(500101, "参数校验异常：%s");
	//登录模块 5002XX
	public static CodeMsg SESSION_ERROR = new CodeMsg(500210, "Session不存在或者已经失效");
	public static CodeMsg PASSWORD_EMPTY = new CodeMsg(500211, "登录密码不能为空");
	public static CodeMsg MOBILE_EMPTY = new CodeMsg(500212, "手机号不能为空");
	public static CodeMsg MOBILE_ERROR = new CodeMsg(500213, "手机号格式错误");
	public static CodeMsg MOBILE_NOT_EXIST = new CodeMsg(500214, "手机号不存在");
	public static CodeMsg PASSWORD_ERROR = new CodeMsg(500215, "密码错误");

	//商品模块 5003XX
	public static CodeMsg GOODS_NOT_EXIST = new CodeMsg(500301, "该商品不存在或审核状态不对");

	//订单模块 5004XX

	//秒杀模块 5005XX
	public static CodeMsg MIAO_SHA_OVER = new CodeMsg(500500, "商品已经秒杀完毕");
	public static CodeMsg REPEATE_MIAOSHA = new CodeMsg(500501, "不能重复秒杀");
	
	private CodeMsg(int code, String msg) {
		this.code = code;
		this.msg = msg;
	}
	public int getCode() {
		return code;
	}
	public String getMsg() {
		return msg;
	}

	/**
	 * 填充异常报文
	 * @params [args]
	 * @returns com.dc.seckill.result.CodeMsg
	 */
	public CodeMsg fillArgs(Object... args){
		int code = this.code;
		String message = String.format(this.msg, args);
		return new CodeMsg(code,message);
	}

	@Override
	public String toString() {
		return "CodeMsg{" +
				"code=" + code +
				", msg='" + msg + '\'' +
				'}';
	}
}
